package org.test.portlet;

import java.io.IOException;
import java.io.PrintWriter;

import javax.portlet.Event;
import javax.portlet.EventRequest;
import javax.portlet.EventResponse;
import javax.portlet.GenericPortlet;
import javax.portlet.PortletException;
import javax.portlet.ProcessEvent;
import javax.portlet.RenderMode;
import javax.portlet.RenderRequest;
import javax.portlet.RenderResponse;

public class HelloPortlet extends GenericPortlet {

	@RenderMode(name = "VIEW")
	public void view(RenderRequest request, RenderResponse response)
			throws PortletException, IOException {
		PrintWriter pw = response.getWriter();
		String name = request.getParameter("name");
		name = (name == null) ? "" : name;
		pw.write("Hello " + name + " !");
	}

	@ProcessEvent(qname = "{http://test.portlet.org}name")
	@Override
	public void processEvent(EventRequest request, EventResponse response)
			throws PortletException, IOException {
		Event event = request.getEvent();
		String name = (String) event.getValue();
		response.setRenderParameter("name", name);
	}
}
